
#ifndef __UDBMLEADER_H__
#define __UDBMLEADER_H__

#pragma once

#include "zdbgrip.h"
#include "zdbmleaderstyle.h"
#include "zdbents.h"

const int MAX_LEADER_NUMBER     = 5000;
const int MAX_LEADERLINE_NUMBER = 5000;

class UcDbMLeaderObjectContextData;

class UcDbMLeader : public UcDbEntity
{
public:

    enum MoveType {
        kMoveAllPoints                  = 0,
        kMoveAllExceptArrowHeaderPoints = 1,
        kMoveContentAndDoglegPoints     = 2
    };
    enum gsMarkType {
        kNone               = 0,
        kArrowMark          = 1,
        kLeaderLineMark     = kArrowMark  + MAX_LEADERLINE_NUMBER,
        kDoglegMark         = kLeaderLineMark + MAX_LEADERLINE_NUMBER,
        kMTextMark          = kDoglegMark + MAX_LEADER_NUMBER,
        kMTextUnderLineMark = kMTextMark + 1,
        kToleranceMark      = kMTextUnderLineMark + 1,
        kBlockMark          = kToleranceMark + 1,
        kBlockAttribute     = kBlockMark + 1
    };
    enum PropertyOverrideType {
        kLeaderLineType         = 0,
        kLeaderLineColor        = 1,
        kLeaderLineTypeId       = 2,
        kLeaderLineWeight       = 3,
        kEnableLanding          = 4,
        kLandingGap             = 5,
        kEnableDogleg           = 6,
        kDoglegLength           = 7,
        kArrowSymbolId          = 8,
        kArrowSize              = 9,
        kContentType            = 10,
        kTextStyleId            = 11,
        kTextLeftAttachmentType     = 12,
        kTextAngleType          = 13,
        kTextAlignmentType      = 14,
        kTextColor              = 15,
        kTextHeight             = 16,
        kEnableFrameText        = 17,
        kDefaultMText           = 18,
        kBlockId                = 19,
        kBlockColor             = 20,
        kBlockScale             = 21,
        kBlockRotation          = 22,
        kBlockConnectionType    = 23,
        kScale                  = 24,
        kTextRightAttachmentType = 25,
        kTextSwitchAlignmentType = 26,
        kTextAttachmentDirection = 27,
        kTextTopAttachmentType = 28,
        kTextBottomAttachmentType = 29,
		kExtendLeaderToText      = 30,
        kSize = kExtendLeaderToText + 1
    };

    UcDbMLeader();

    ~UcDbMLeader();

    UCDB_DECLARE_MEMBERS(UcDbMLeader);

    virtual Ucad::ErrorStatus dwgInFields (UcDbDwgFiler* filer);

    virtual Ucad::ErrorStatus dwgOutFields(UcDbDwgFiler* filer) const;

    virtual Ucad::ErrorStatus dxfInFields (UcDbDxfFiler* filer);

    virtual Ucad::ErrorStatus dxfOutFields(UcDbDxfFiler* filer) const;
    virtual ZSoft::Boolean    worldDraw   (UcGiWorldDraw* mode);
    virtual void              viewportDraw(UcGiViewportDraw* mode);
    virtual Ucad::ErrorStatus transformBy (const UcGeMatrix3d& xform);
    virtual Ucad::ErrorStatus getStretchPoints           (UcGePoint3dArray& stretchPoints) const;
    virtual Ucad::ErrorStatus moveStretchPoints          (const UcDbIntArray& indices,
                                                          const UcGeVector3d& offset);
    virtual Ucad::ErrorStatus getGripPoints              (UcDbGripDataPtrArray& grips,
                                                          const double curViewUnitSize,
                                                          const int gripSize,
                                                          const UcGeVector3d& curViewDir,
                                                          const int bitflags) const;
    virtual Ucad::ErrorStatus moveGripPointsAt           (const UcDbVoidPtrArray& gripAppData,
                                                          const UcGeVector3d& offset,
                                                          const int bitflags);
    virtual Ucad::ErrorStatus getSubentPathsAtGsMarker   (UcDb::SubentType     type,
                                                          ZSoft::GsMarker      gsMark,
                                                          const UcGePoint3d&   pickPoint,
                                                          const UcGeMatrix3d&  viewXform,
                                                          int&                 numPaths,
                                                          UcDbFullSubentPath*& subentPaths,
                                                          int                  numInserts = 0,
                                                          UcDbObjectId*        entAndInsertStack = NULL) const;
    virtual Ucad::ErrorStatus getGsMarkersAtSubentPath   (const UcDbFullSubentPath& subPath,
                                                          UcArray<ZSoft::GsMarker>& gsMarkers) const;
    virtual Ucad::ErrorStatus getGripPointsAtSubentPath  (const UcDbFullSubentPath& path,
                                                          UcDbGripDataPtrArray& grips,
                                                          const double curViewUnitSize,
                                                          const int gripSize,
                                                          const UcGeVector3d& curViewDir,
                                                          const int bitflags) const;
    virtual Ucad::ErrorStatus moveGripPointsAtSubentPaths(const UcDbFullSubentPathArray& paths,
                                                          const UcDbVoidPtrArray& gripAppData,
                                                          const UcGeVector3d& offset,
                                                          const int bitflags);
    virtual Ucad::ErrorStatus deleteSubentPaths          (const UcDbFullSubentPathArray& paths);
    virtual UcDbEntity*       subentPtr                  (const UcDbFullSubentPath& path) const;
    virtual Ucad::ErrorStatus getOsnapPoints             (UcDb::OsnapMode     osnapMode,
                                                          ZSoft::GsMarker     gsSelectionMark,
                                                          const UcGePoint3d&  pickPoint,
                                                          const UcGePoint3d&  lastPoint,
                                                          const UcGeMatrix3d& viewXform,
                                                          UcGePoint3dArray&   snapPoints,
                                                          UcDbIntArray&       geomIds) const;
    virtual Ucad::ErrorStatus intersectWith              (const UcDbEntity* pEnt,
                                                          UcDb::Intersect intType,
                                                          const UcGePlane& projPlane,
                                                          UcGePoint3dArray& points,
                                                          ZSoft::GsMarker thisGsMarker = 0,
                                                          ZSoft::GsMarker otherGsMarker = 0) const;
    virtual Ucad::ErrorStatus intersectWith              (const UcDbEntity* pEnt,
                                                          UcDb::Intersect intType,
                                                          UcGePoint3dArray& points,
                                                          ZSoft::GsMarker thisGsMarker = 0,
                                                          ZSoft::GsMarker otherGsMarker = 0) const;
    virtual Ucad::ErrorStatus explode                     (UcDbVoidPtrArray& entitySet) const;
    virtual void              list                        () const;
    virtual Ucad::ErrorStatus getGeomExtents              (UcDbExtents& extents) const;
    virtual Ucad::ErrorStatus subClose                    ();

    virtual Ucad::ErrorStatus subErase                    (ZSoft::Boolean erasing);

    virtual void              objectClosed                (const UcDbObjectId dbObjId);

    virtual void              modified                    (const UcDbObject* dbObj);
    virtual Ucad::ErrorStatus getClassID                  (CLSID* pClsid) const;
    virtual Ucad::ErrorStatus getGripEntityUCS            (const void* pGripAppData,
                                                           UcGeVector3d& normalVec,
                                                           UcGePoint3d& origin,
                                                           UcGeVector3d& xAxis) const;
    virtual void              gripStatus                  (const UcDb::GripStat status);
    virtual Ucad::ErrorStatus highlight                   (const UcDbFullSubentPath& subId = kNullSubent,
                                                           const ZSoft::Boolean highlightAll = false) const;
    virtual Ucad::ErrorStatus unhighlight                 (const UcDbFullSubentPath& subId = kNullSubent,
                                                           const ZSoft::Boolean highlightAll = false) const;
    virtual Ucad::ErrorStatus getTransformedCopy          (const UcGeMatrix3d& xform,
                                                           UcDbEntity*& pEnt) const;
    Ucad::ErrorStatus         setOverride                 (PropertyOverrideType propertyType,
                                                           bool isOverride = true);

    bool                      isOverride                  (PropertyOverrideType propertyType) const;

    Ucad::ErrorStatus         setScale                    (double scale);

    double                    scale                       () const;

    Ucad::ErrorStatus         getBlockAttributeValue(const UcDbObjectId& attdefId,
                                                     UcDbAttribute*& pAtt) const;

    Ucad::ErrorStatus         setBlockAttributeValue(const UcDbObjectId& attdefId,
                                                     const UcDbAttribute* pAtt);

    Ucad::ErrorStatus         getBlockAttributeValue      (const UcDbObjectId& attdefId,
                                                           ZTCHAR*& value) const;

    Ucad::ErrorStatus         setBlockAttributeValue      (const UcDbObjectId& attdefId,
                                                           const ZTCHAR* value);

    UcGePlane         plane               () const;

    void              setPlane            (const UcGePlane& plane);

    UcGeVector3d      normal              () const;

    Ucad::ErrorStatus moveMLeader         (const UcGeVector3d& vector,
                                           MoveType moveType,
                                           bool bAutoSwitchDogleg = true);

    Ucad::ErrorStatus getContentGeomExtents(UcDbExtents& extents) const;

    int               numLeaders          () const;

    Ucad::ErrorStatus getLeaderIndexes(UcArray<int>& leaderIndexes) const;

    Ucad::ErrorStatus addLeader           (int& leaderIndex);

    Ucad::ErrorStatus removeLeader        (int leaderIndex);

    int               numLeaderLines      () const;

    Ucad::ErrorStatus getLeaderLineIndexes(UcArray<int>& leaderLineIndexes) const;

    Ucad::ErrorStatus addLeaderLine       (int leaderIndex, int& leaderLineIndex);

    Ucad::ErrorStatus addLeaderLine       (const UcGePoint3d& point, int& leaderLineIndex);

    Ucad::ErrorStatus removeLeaderLine    (int leaderLineIndex);

    Ucad::ErrorStatus addFirstVertex      (int leaderLineIndex, const UcGePoint3d& point);

    Ucad::ErrorStatus removeFirstVertex   (int leaderLineIndex);

    Ucad::ErrorStatus getFirstVertex      (int leaderLineIndex, UcGePoint3d& point) const;

    Ucad::ErrorStatus setFirstVertex      (int leaderLineIndex, const UcGePoint3d& point);

    Ucad::ErrorStatus addLastVertex       (int leaderLineIndex, const UcGePoint3d& point);

    Ucad::ErrorStatus removeLastVertex    (int leaderLineIndex);

    Ucad::ErrorStatus getLastVertex       (int leaderLineIndex, UcGePoint3d& point) const;

    Ucad::ErrorStatus setLastVertex       (int leaderLineIndex, const UcGePoint3d& point);

    Ucad::ErrorStatus numVertices         (int leaderLineIndex, int& num) const;

    Ucad::ErrorStatus setVertex           (int leaderLineIndex, int index, const UcGePoint3d& point);

    Ucad::ErrorStatus getVertex           (int leaderLineIndex, int index, UcGePoint3d& point) const;

    Ucad::ErrorStatus getLeaderIndex      (int leaderLineIndex, int& leaderIndex) const;

    Ucad::ErrorStatus getLeaderLineIndexes(int leaderIndex, UcArray<int>& leaderLineIndexes) const;

    Ucad::ErrorStatus setDoglegDirection           (int leaderIndex, const UcGeVector3d& vector);

    Ucad::ErrorStatus getDoglegDirection           (int leaderIndex, UcGeVector3d& vector) const;

    Ucad::ErrorStatus                     setLeaderLineType      (UcDbMLeaderStyle::LeaderType leaderLineType);

    UcDbMLeaderStyle::LeaderType          leaderLineType         () const;
    Ucad::ErrorStatus setLeaderLineType(int leaderLineIndex,
                                        UcDbMLeaderStyle::LeaderType  leaderLineType);

    Ucad::ErrorStatus getLeaderLineType(int leaderLineIndex,
                                        UcDbMLeaderStyle::LeaderType& leaderLineType) const;
    Ucad::ErrorStatus                     setLeaderLineColor     (const UcCmColor& leaderLineColor);

    UcCmColor                             leaderLineColor        () const;
    Ucad::ErrorStatus setLeaderLineColor(int leaderLineIndex,
                                         const UcCmColor& leaderLineColor);

    Ucad::ErrorStatus getLeaderLineColor(int leaderLineIndex,
                                         UcCmColor& leaderLineColor) const;
    Ucad::ErrorStatus                     setLeaderLineTypeId    (UcDbObjectId leaderLineTypeId);

    UcDbObjectId                          leaderLineTypeId       () const;
    Ucad::ErrorStatus setLeaderLineTypeId(int leaderLineIndex,
                                         UcDbObjectId  leaderLineTypeId);

    Ucad::ErrorStatus getLeaderLineTypeId(int leaderLineIndex,
                                         UcDbObjectId& leaderLineTypeId) const;
    Ucad::ErrorStatus                     setLeaderLineWeight    (UcDb::LineWeight leaderLineWeight);

    UcDb::LineWeight                      leaderLineWeight       () const;
    Ucad::ErrorStatus setLeaderLineWeight(int leaderLineIndex,
                                          UcDb::LineWeight  leaderLineWeight);

    Ucad::ErrorStatus getLeaderLineWeight(int leaderLineIndex,
                                          UcDb::LineWeight& leaderLineWeight) const;
    Ucad::ErrorStatus                     setLandingGap          (double landingGap);

    double                                landingGap             () const;

    Ucad::ErrorStatus                     setEnableLanding       (bool enableLanding);

    bool                                  enableLanding          () const;

    Ucad::ErrorStatus                     setEnableDogleg        (bool enableDogleg);

    bool                                  enableDogleg           () const;

    Ucad::ErrorStatus                     setDoglegLength        (int leaderIndex, double doglegLength);

    Ucad::ErrorStatus                     doglegLength           (int leaderIndex, double& doglegLength) const;

    Ucad::ErrorStatus                     setDoglegLength        (double doglegLength);

    double                                doglegLength           () const;

    Ucad::ErrorStatus                     setArrowSymbolId       (UcDbObjectId arrowSymbolId);

    UcDbObjectId                          arrowSymbolId          () const;

    Ucad::ErrorStatus getArrowSymbolId(int leaderLineIndex,
                                       UcDbObjectId& arrowSymbolId) const;

    Ucad::ErrorStatus                     setArrowSize           (double arrowSize);

    double                                arrowSize              () const;
    Ucad::ErrorStatus setArrowSize(int leaderLineIndex, double  arrowSize);

    Ucad::ErrorStatus getArrowSize(int leaderLineIndex, double& arrowSize) const;
    Ucad::ErrorStatus                     setContentType         (UcDbMLeaderStyle::ContentType contentType);

    UcDbMLeaderStyle::ContentType         contentType            () const;

    Ucad::ErrorStatus                     setTextStyleId         (UcDbObjectId textStyleId);

    UcDbObjectId                          textStyleId            () const;

    Ucad::ErrorStatus                     setTextAttachmentType  (UcDbMLeaderStyle::TextAttachmentType textAttachmentType,
                                                                  UcDbMLeaderStyle::LeaderDirectionType leaderDirection);

    UcDbMLeaderStyle::TextAttachmentType  textAttachmentType     (UcDbMLeaderStyle::LeaderDirectionType leaderDirection) const;

    Ucad::ErrorStatus                     setTextAttachmentType  (UcDbMLeaderStyle::TextAttachmentType textAttachmentType);

    UcDbMLeaderStyle::TextAttachmentType  textAttachmentType     () const;

    Ucad::ErrorStatus                     setTextAngleType       (UcDbMLeaderStyle::TextAngleType textAngleType);

    UcDbMLeaderStyle::TextAngleType       textAngleType          () const;

    Ucad::ErrorStatus                     setTextAlignmentType   (UcDbMLeaderStyle::TextAlignmentType textAlignmentType);

    UcDbMLeaderStyle::TextAlignmentType   textAlignmentType      () const;

    Ucad::ErrorStatus                     setTextColor           (const UcCmColor& textColor);

    UcCmColor                             textColor              () const;

    Ucad::ErrorStatus                     setTextHeight          (double textHeight);

    double                                textHeight             () const;

    Ucad::ErrorStatus                     setEnableFrameText     (bool enableFrameText);

    bool                                  enableFrameText        () const;

    Ucad::ErrorStatus                     setMText               (const UcDbMText* pMText);

    UcDbMText*                            mtext                  () const;

    Ucad::ErrorStatus                     setBlockContentId             (UcDbObjectId blockId);

    UcDbObjectId                          blockContentId                () const;

    Ucad::ErrorStatus                     setBlockColor          (const UcCmColor& blockColor);

    UcCmColor                             blockColor             () const;

    Ucad::ErrorStatus                     setBlockScale          (const UcGeScale3d& scale);

    UcGeScale3d                           blockScale             () const;

    Ucad::ErrorStatus                     setBlockRotation       (double rotation);

    double                                blockRotation          () const;

    Ucad::ErrorStatus                     setBlockConnectionType (UcDbMLeaderStyle::BlockConnectionType blockConnectionType);

    UcDbMLeaderStyle::BlockConnectionType blockConnectionType    () const;

    Ucad::ErrorStatus                     setEnableAnnotationScale(bool enableAnnotationScale);

    bool                                  enableAnnotationScale   () const;

    Ucad::ErrorStatus                     setMLeaderStyle        (UcDbObjectId newStyleId);

    UcDbObjectId                          MLeaderStyle           ();

    Ucad::ErrorStatus                     getOverridedMLeaderStyle(UcDbMLeaderStyle& mleaderStyle);

    Ucad::ErrorStatus                     setContextDataManager  (void* pContextDataManager);

    void*                                 getContextDataManager  () const;

    Ucad::ErrorStatus                     setBlockPosition       (const UcGePoint3d& position);

    Ucad::ErrorStatus                     getBlockPosition       (UcGePoint3d& position) const;

    Ucad::ErrorStatus                     setTextLocation        (const UcGePoint3d& location);

    Ucad::ErrorStatus                     getTextLocation        (UcGePoint3d& location) const;

    Ucad::ErrorStatus                     setToleranceLocation   (const UcGePoint3d& location);

    Ucad::ErrorStatus                     getToleranceLocation   (UcGePoint3d& location) const;
    Ucad::ErrorStatus                     setArrowSymbolId       (int leaderLineIndex,
                                                                  UcDbObjectId arrowSymbolId);

    UcDbObjectId                          arrowSymbolId          (int leaderLineIndex) const;

    bool                                  hasContent             () const;

    Ucad::ErrorStatus                     connectionPoint        (const UcGeVector3d& vect,
                                                                  UcGePoint3d& point) const;
    Ucad::ErrorStatus                     connectionPoint        (const UcGeVector3d& vect,
                                                                  UcGePoint3d& point,
                                                                  UcDbMLeaderStyle::TextAttachmentDirection textAttachmentDirection) const;
    Ucad::ErrorStatus                     recomputeBreakPoints   ();

    Ucad::ErrorStatus                     postMLeaderToDb        (UcDbDatabase* pDb);

    Ucad::ErrorStatus                     updateLeaderLinePosition();

    Ucad::ErrorStatus                     removeLeaderLineRefAssoc(int leaderLineIndex) const;

    Ucad::ErrorStatus                     updateContentScale(UcDbMLeaderObjectContextData* pContext);
    Ucad::ErrorStatus                     setTextAttachmentDirection(UcDbMLeaderStyle::TextAttachmentDirection textAttachmentDirection);

    UcDbMLeaderStyle::TextAttachmentDirection textAttachmentDirection() const;

	Ucad::ErrorStatus                     setExtendLeaderToText(bool value);
	bool                                  extendLeaderToText() const;
protected:

    virtual Ucad::ErrorStatus subGetClassID                  (CLSID* pClsid) const;
};

#endif

